if(!jsx3.lang.Class.forName("ux.cdb.admin.mechanism.schema.loanassist.builder.SchemaLoanAssistCmp")) {
	jsx3.lang.Class.defineClass("ux.cdb.admin.mechanism.schema.loanassist.builder.SchemaLoanAssistCmp",
			ux.megatron.gui.WizardPanel,
			null,
			function (objRoot) {
		objRoot.prototype.btnAdd = null; //add button
        objRoot.prototype.btnEdit = null; //edit button
        objRoot.prototype.btnDelete = null; //delete button
        objRoot.prototype.matrix = null;//matrix
        objRoot.prototype.canEdit = false;//whether the record can edit
        objRoot.prototype.blkExpend = null;//the panel which contain the buttons "save&cancel"
        objRoot.prototype.initRecords=null;//save the content befor edit
        objRoot.prototype.wizard=null;
        /*
         * This method will be called after UI file has deserialized.
         */
        objRoot.prototype.onAfterDeserialize = function(){
        	
			
        }
        objRoot.prototype.ruleChecked = function(){
        	if (this.matrix.getCheckedNodes().size()>0)
			{
				this.btnDelete.setEnabled(jsx3.gui.Form.STATEENABLED, true);
			}
			else
			{
				this.btnDelete.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
			}
		}
		objRoot.prototype.onAdd = function(){
			//user click add button 
			//enter the add mode
			this.canEdit=true;
			//save the records for revert
			this.initRecords=this.matrix.getXML().cloneDocument();
			//insert a new record
			var record=this.matrix.insertRecord({jsxid:jsx3.xml.CDF.getKey()},null,false);
			this.matrix.repaintData();
			//show save&canel button
			this.blkExpend.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
		}

		objRoot.prototype.onEdit = function(){
			if (this.canEdit == false) {//if current not eidt mode, then change the statue to edit mode
				this.canEdit = true;
				//save the records for revert
				this.initRecords=this.matrix.getXML().cloneDocument();
				this.blkExpend.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
			}
		}
		objRoot.prototype.onDelete= function(){
			var server=ux.megatron.Main.getServer();
			if (this.canEdit)
			{
				server.confirm(server.getDynamicProperty("@cdb@Mechanism@Schema@Alert"),server.getDynamicProperty("@cdb@Mechanism@Schema@CancelEdit"),this.callDeleteRecord,null);
			}
		}
		objRoot.prototype.callDeleteRecord=function(objEvent)
		{//call service to delete the selected record
			objEvent.doClose();//close the confirm window
			if (this.canEdit) {
			//cancel the edit
			//revert the record
			
			}
		}
		objRoot.prototype.onSave = function(){
			//here to save
			
			//out the edit mode
			this.canEdit=false;
			//hidde the button save&cancel
			this.blkExpend.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
		}
		objRoot.prototype.onCmpCancel = function(){
			//here to cancel
			//out the edit mode
			//rever the data
			this.matrix.getXML().loadXML(this.initRecords.toString());
			this.matrix.repaintData();
			//hidde the button save&cancel
			this.blkExpend.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
			this.canEdit=false;
		}
		objRoot.prototype.getCanEdit = function(){
			return this.canEdit;
		}
		objRoot.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
	
			//call constructor for super class (the super expects the name of the object and the function that it is an instance of)
			this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
		};

		objRoot.prototype.initialize = function(msg) {
			//this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
			var me=this;
            this.btnAdd = this.getDescendantOfName("btn_Cmp_add");
            this.btnEdit = this.getDescendantOfName("btn_Cmp_edit");
            this.btnDelete = this.getDescendantOfName("btn_Cmp_delete");
            this.blkExpend=this.getDescendantOfName("blkExpend");
			this.matrix=this.getDescendantOfName("mtxEditCmp");
			this.matrix.subscribe(ux.cdb.admin.gui.Matrix.EVENT_CHECKALL, me, me.ruleChecked);
			this.wizard=this.getAncestorOfType("ux.cdb.admin.mechanism.schema.SchemaWizard");
			
			if (this.wizard.isEdit)
			{
				this.getDescendantOfName("blkOverflowbandratio").setDataByObject(this.wizard.editMessage);
				this.getDescendantOfName("txtCmpOthers").setValue(this.wizard.cmpother);
				this.getDescendantOfName("blkCmpRatio").getDescendantOfName("txtValue").setValue(this.wizard.cmpRatio);
				this.getDescendantOfName("blkOverflowbandratio").setDataByObject({cdbChargeLossPct:this.wizard.cdbChargeLossPct,cooperOrgChargeLossPct:this.wizard.cooperOrgChargeLossPct});;
			}
			this.matrix.repaintData();
			this.matrix.focus();
		}

		objRoot.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			//validate the user input
			if(this.doValidate()!=true)
			{//validate failure
			
				this.getAncestorOfType("ux.cdb.admin.mechanism.schema.loanassist.builder.Builder").setWarnMessage(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@Schema@ValidateFailure"));
				return "NONE";//not close the wizard
			}
			this.getAncestorOfType("ux.cdb.admin.mechanism.schema.loanassist.builder.Builder").clearWarnMessage();
			return null; //close  the wizard 
		}
		/**
		 * the function to validate the user input
		 */
		objRoot.prototype.doValidate=function()
		{
			
			//alert(this.matrix.getChildNodes());
			var nodes=this.matrix.getXML().getChildNodes();
			var server=ux.megatron.Main.getServer();
			var numericValidator=ux.megatron.util.ValidationManager.getValidator("Numeric");
			var vldContent=["jsxcenter","jsxprovince","jsxcity","jsxcounty","jsxothers"];
			var count;
			//validate matrix
			for(var i=0;i<nodes.size();i++)
			{
				count=0;
				for (var j = 0; j < vldContent.length; j++) {
					this.message = numericValidator(nodes.get(i).getAttribute(vldContent[j]));
					if (this.message != null) {
						return "@cdb@Mechanism@Schema@ValidateFailure";
					}
					if (parseInt(nodes.get(i).getAttribute(vldContent[j]))<0)
					{
						return "@cdb@Mechanism@Schema@MatrixRatioNegative";
					}
					count=count+nodes.get(i).getAttribute(vldContent[j])*1;
				}
				//validate the count
				if (count!=100)
				{
					return "@cdb@Mechanism@Schema@MatrixRatioValidate";
				}
				
			}
			//validate other content
			if (this.getDescendantOfName("blkCmpRatioField").doValidate()!=null)
			{
				return "@cdb@Mechanism@Schema@ValidateFailure";
			}
			

			if (this.getDescendantOfName("blkCmpRatioField").getDescendantOfName("txtValue").getValue()>100 || this.getDescendantOfName("blkCmpRatioField").getDescendantOfName("txtValue").getValue()<0 )
			{
				this.getDescendantOfName("blkCmpRatio")._validateFailedUI(true,server.getDynamicProperty("@cdb@Mechanism@Schema@CompRatioLimit"));
				return "@cdb@Mechanism@Schema@CompRatioLimit";
			}
			else
			{
				this.getDescendantOfName("blkCmpRatio")._validateFailedUI(false,"");
			} 
			
			
			//validate the count of the cdb&gov
			if (this.getDescendantOfName("blkOverflowbandratio").doValidate()!=null)
			{
				return "@cdb@Mechanism@Schema@ValidateFailure";
			}
		
			var count=this.getDescendantOfName("blkOverflowbandratio").getDescendantsOfType("jsx3.gui.TextBox"); 
			if ((parseInt(count[0].getValue())+parseInt(count[1].getValue()))!=100)
			{
				count[0].getAncestorOfType("ux.cdb.admin.dataautomate.TxtUpdater")._validateFailedUI(true,server.getDynamicProperty("@cdb@Mechanism@Schema@RiskRatioLimit"));
				count[1].getAncestorOfType("ux.cdb.admin.dataautomate.TxtUpdater")._validateFailedUI(true,server.getDynamicProperty("@cdb@Mechanism@Schema@RiskRatioLimit"));
				return "@cdb@Mechanism@Schema@RiskRatioLimit";
			}
			else
			{
				count[0].getAncestorOfType("ux.cdb.admin.dataautomate.TxtUpdater")._validateFailedUI(false,"");
				count[1].getAncestorOfType("ux.cdb.admin.dataautomate.TxtUpdater")._validateFailedUI(false,"");
			}
			
			return null;
		}
		objRoot.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			
			var val=this.doValidate();
			if(val!=null)
			{//validate failure
			
				this.getAncestorOfType("ux.cdb.admin.mechanism.schema.loanassist.builder.Builder").setWarnMessage(ux.megatron.Main.getServer().getDynamicProperty(val));
				return "NONE";//not close the wizard
			}
			this.getAncestorOfType("ux.cdb.admin.mechanism.schema.loanassist.builder.Builder").clearWarnMessage();
			return null; // return "NONE" to not advance panels
		}

		objRoot.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			return null; // return "NONE" to not last status
		}

		objRoot.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			this.getAncestorOfType("ux.cdb.admin.mechanism.schema.SchemaWizard").onCancel();
			return null; // return "NONE" to not advance panels
		}

		objRoot.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
			return null; // return "NONE" to not advance panels
		}

		objRoot.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
			if(!this.getChild(0)) {
				var me = this;
				ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/mechanism/schema/loanassist/builder/step3/ui/SchemaLoanAssistCmpContent.xml", me, me.initialize);
			}
			return null; // return "NONE" to not advance panels
		}
		objRoot.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
			//user clicked finish  assemble the object
			//validate the user input
			var val=this.doValidate();
			if(val!=null)
			{//validate failure
			
				this.getAncestorOfType("ux.cdb.admin.mechanism.schema.loanassist.builder.Builder").setWarnMessage(ux.megatron.Main.getServer().getDynamicProperty(val));
				return "NONE";//not close the wizard
			}
			this.getAncestorOfType("ux.cdb.admin.mechanism.schema.loanassist.builder.Builder").clearWarnMessage();
			this.saveSchema();
		}
		
		/**
		 * 
		 * to save information
		 */
		objRoot.prototype.saveSchema=function()
		{

			if (this.wizard==null)
			{
				this.wizard = this.getAncestorOfType("ux.cdb.admin.mechanism.schema.SchemaWizard");
			}

			//get the data about baseinfo
			var me = this;
			//get the baseinfo
			var data = this.wizard.getDescendantOfName("blkSchemaLoanAssistBaseinfo").getDataAsObject();

			var intInfo;
			if (this.wizard.getDescendantOfName("mtxEditInterest")!= null) 
			{
				//get interest ratio from matrix			
				intInfo = this.wizard.getDescendantOfName("mtxEditInterest").getXML().getChildNodes();
			}
			else 
			{
				//get interest ration from cache
				intInfo=ux.megatron.Main.getServer().getCache().getDocument("cchLoanAssistInterestList").getChildNodes();
			}
			//add the intInfo into data
			data.enrollTypeCodeSubsidy1=intInfo.get(0).getAttribute("jsxid");//类型：学生考入中央院校	
			data.centralFinanceSubsidyPct1 = intInfo.get(0).getAttribute("jsxcenter");//中央分担比例
			data.provinceFinanceSubsidyPct1 = intInfo.get(0).getAttribute("jsxprovince");//省分担比例
			data.cityFinanceSubsidyPctSubsidy1 = intInfo.get(0).getAttribute("jsxcity");//市分担比例
			data.countyFinanceSubsidyPct1 = intInfo.get(0).getAttribute("jsxcounty");//县分担比例
			data.otherPartSubsidyPct1 = intInfo.get(0).getAttribute("jsxothers");//其他分担比例
			var intOtherName; 
			if (this.wizard.getDescendantOfName("txtInterestOthers"))
			{//if we can find content
				intOtherName= this.wizard.getDescendantOfName("txtInterestOthers").getValue();
			}
			else
			{
				if (this.wizard.isEdit) 
				{
					intOtherName=this.wizard.interestother;
				}
				else 
				{
					intOtherName = "";
				}
			}

			data.otherSharePartyNameSubsidy1 = intOtherName;//其他名称
			
			data.enrollTypeCodeSubsidy2=intInfo.get(1).getAttribute("jsxid");//类型：学生考入地方高校，跨省就读	
			data.centralFinanceSubsidyPct2 = intInfo.get(1).getAttribute("jsxcenter");//中央分担比例
			data.provinceFinanceSubsidyPct2 = intInfo.get(1).getAttribute("jsxprovince");//省分担比例
			data.cityFinanceSubsidyPctSubsidy2 = intInfo.get(1).getAttribute("jsxcity");//市分担比例
			data.countyFinanceSubsidyPct2 = intInfo.get(1).getAttribute("jsxcounty");//县分担比例
			data.otherPartSubsidyPct2 = intInfo.get(1).getAttribute("jsxothers");//其他分担比例
			data.otherSharePartyNameSubsidy2 = intOtherName;//其他名称
			
			data.enrollTypeCodeSubsidy3=intInfo.get(2).getAttribute("jsxid");//类型：学生考入地方高校，本省就读
			data.centralFinanceSubsidyPct3 = intInfo.get(2).getAttribute("jsxcenter");//中央分担比例
			data.provinceFinanceSubsidyPct3 = intInfo.get(2).getAttribute("jsxprovince");//省分担比例
			data.cityFinanceSubsidyPctSubsidy3 = intInfo.get(2).getAttribute("jsxcity");//市分担比例
			data.countyFinanceSubsidyPct3 = intInfo.get(2).getAttribute("jsxcounty");//县分担比例
			data.otherPartSubsidyPct3 = intInfo.get(2).getAttribute("jsxothers");//其他分担比例
			data.otherSharePartyNameSubsidy3 = intOtherName;//其他名称
			//get compensate ratio
			if (this.wizard.getDescendantOfName("blkCmpRatio"))
			{
				data.riskSharePct = this.wizard.getDescendantOfName("blkCmpRatio").getDescendantOfName("txtValue").getValue();
			}
			else
			{
				if (this.wizard.isEdit)
				{
					data.riskSharePct = this.wizard.cmpRatio;
				}
				else
				{
					data.riskSharePct="15";
				}
			}


			var cmpInfo=null;
			if (this.wizard.getDescendantOfName("mtxEditCmp")!=null)
			{
				cmpInfo= this.wizard.getDescendantOfName("mtxEditCmp").getXML().getChildNodes();
			}
			else
			{
				cmpInfo=ux.megatron.Main.getServer().getCache().getDocument("cchLoadAssistCmpList").getChildNodes();
			}
			 
			data.enrollTypeCode1=cmpInfo.get(0).getAttribute("jsxid");//学生考入中央院校
			data.centralFinanceSharedPct1 = cmpInfo.get(0).getAttribute("jsxcenter");//中央分担比例
			data.provinceFinanceSharePct1 = cmpInfo.get(0).getAttribute("jsxprovince");//省分担比例
			data.cityFinanceSubsidyPct1 = cmpInfo.get(0).getAttribute("jsxcity");//市分担比例
			data.countyFinanceSharePct1 = cmpInfo.get(0).getAttribute("jsxcounty");//县分担比例
			data.otherPartSharePct1 = cmpInfo.get(0).getAttribute("jsxothers");//其他分担比例
			var cmpName;
			if (this.wizard.getDescendantOfName("txtCmpOthers"))
			{//if we can find the content
				cmpName =this.wizard.getDescendantOfName("txtCmpOthers").getValue();//其他名称
				
			}
			else
			{
				if (this.wizard.isEdit) 
				{
					cmpName=this.wizard.cmpother;
				}
				else 
				{
					cmpName = "";
				}
			}

			data.otherSharePartyName1 = cmpName;//其他分担比例
			data.enrollTypeCode2=cmpInfo.get(1).getAttribute("jsxid");//学生考入地方高校，跨省就读
			data.centralFinanceSharedPct2 = cmpInfo.get(1).getAttribute("jsxcenter");//中央分担比例
			data.provinceFinanceSharePct2 = cmpInfo.get(1).getAttribute("jsxprovince");//省分担比例
			data.cityFinanceSubsidyPct2 = cmpInfo.get(1).getAttribute("jsxcity");//市分担比例
			data.countyFinanceSharePct2 = cmpInfo.get(1).getAttribute("jsxcounty");//县分担比例
			data.otherPartSharePct2 = cmpInfo.get(1).getAttribute("jsxothers");//其他分担比例
			data.otherSharePartyName2 = cmpName;//其他分担比例
			
			data.enrollTypeCode3=cmpInfo.get(2).getAttribute("jsxid");//学生考入地方高校，本省就读
			data.centralFinanceSharedPct3 = cmpInfo.get(2).getAttribute("jsxcenter");//中央分担比例
			data.provinceFinanceSharePct3 = cmpInfo.get(2).getAttribute("jsxprovince");//省分担比例
			data.cityFinanceSubsidyPct3 = cmpInfo.get(2).getAttribute("jsxcity");//市分担比例
			data.countyFinanceSharePct3 = cmpInfo.get(2).getAttribute("jsxcounty");//县分担比例
			data.otherPartSharePct3 = cmpInfo.get(2).getAttribute("jsxothers");//其他分担比例
			data.otherSharePartyName3 = cmpName;//其他分担比例
			data.partybName=this.wizard.getDescendantOfName("blkCenterName").getDescendantOfName("selValue").getText();
			
			
			//put the "超出风险补偿资金的贷款损失分担比例" into object
			if (this.wizard.getDescendantOfName("blkOverflowbandratio")) 
			{
				var overRisk = this.wizard.getDescendantOfName("blkOverflowbandratio").getDataAsObject();
				
				data.cdbChargeLossPct = overRisk.cdbChargeLossPct;
				data.cooperOrgChargeLossPct = overRisk.cooperOrgChargeLossPct;
			}
			else
			{
				if (this.wizard.isEdit)
				{
					data.cdbChargeLossPct =this.wizard.cdbChargeLossPct;
					
					data.cooperOrgChargeLossPct = this.wizard.cooperOrgChargeLossPct;
				}
				else
				{
					data.cdbChargeLossPct = "50";
					data.cooperOrgChargeLossPct = "50";
				}
			}
			if (!this.wizard.isEdit) {
				//add mode
				ux.megatron.util.Dwr.callDwr("AddCooperAgreementUCC", "saveCooperAgreementInfo", [data, "004"], me, me.schemaMessageSaved);

			}
			else{
				//edit mode
				data.cooperAgreementBasicInfoId=this.wizard.baseinfoid; //evaluate the id 
				data.cooperAgmtDetailInfoId=this.wizard.cooperAgmtDetailInfoId;
				
				data.acctId=this.wizard.acctId;               
				data.subsidyPctId1=this.wizard.subsidyPctId1;         
				data.subsidyPctId2=this.wizard.subsidyPctId2;       
				data.subsidyPctId3=this.wizard.subsidyPctId3;        
				data.riskCompensationPctId1=this.wizard.riskCompensationPctId1;
				data.riskCompensationPctId2=this.wizard.riskCompensationPctId2;
				data.riskCompensationPctId3=this.wizard.riskCompensationPctId3;
				//the up is all the id needed by UCC 
				ux.megatron.util.Dwr.callDwr("MaintainCooperAgreementUCC", "updateCooperAgreement", [data,"004"], me, me.schemaMessageSaved);

			}
			console.log("\r\r\t send schema info to save :\r\t"+ux.megatron.util.JSON.JSONtoString(data)+"\r\r");
		}
		
		
		//schema message saved
		objRoot.prototype.schemaMessageSaved=function(message)
		{//received the back message close wizard
			if (this.wizard.isEdit) 
			{
				if (message.res.flag == 1) 
				{
					alert(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@ModifySchemaNotice"));
				}
				ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.schema.Schema")[0].onRefresh(this.wizard.isEdit);
			
			}
			else
			{
				if (message.res.flag == 1) 
				{
					alert(ux.megatron.Main.getServer().getDynamicProperty("@cdb@Mechanism@CooOrg@AddSchemaNotice"));
				}
				//ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.schema.Schema")[0].getDescendantOfName("blkSearchName").getDescendantOfName("txtValue").setValue(this.wizard.schemaName);
				//ux.megatron.Main.getServer().getBodyBlock().getDescendantsOfType("ux.cdb.admin.mechanism.schema.Schema")[0].onSearch();
			}
			//clear cache
			cmpInfo=ux.megatron.Main.getServer().getCache().clearById("cchLoadAssistCmpList");
			cmpInfo=ux.megatron.Main.getServer().getCache().clearById("cchLoanAssistInterestList");
			this.getAncestorOfType("ux.cdb.admin.mechanism.schema.SchemaWizard").onCancel();
			
		}
		objRoot.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
			return null; // return "NONE" to not advance panels
		}
    });
}
